package com.simulation.web.controller.tech;

import com.simulation.common.core.domain.AjaxResult;
import com.simulation.web.domain.TechUserPostFollow;
import com.simulation.web.service.impl.UserPostFollowServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api("项目-关注")
@RestController
@RequestMapping("techUserPostFollow")
@AllArgsConstructor
public class UserPostFollowController {

    private final UserPostFollowServiceImpl userPostFollowService;

    /**
     * 查询所有记录
     *
     * @return 返回集合，没有返回空List
     */
    @RequestMapping("list")
    public List<TechUserPostFollow> listAll() {
        return userPostFollowService.listAll();
    }


    /**
     * 根据主键查询
     *
     * @param id 主键
     * @return 返回记录，没有返回null
     */
    @RequestMapping("getById")
    public TechUserPostFollow getById(Long id) {
        return userPostFollowService.getById(id);
    }    
     
    /**
     * 新增关注
     *
     * @param techUserPostFollow 新增的记录
     * @return 返回影响行数
     */
    @PostMapping("insert")
    @ApiOperation("新增关注")
    public AjaxResult insert(@RequestBody TechUserPostFollow techUserPostFollow) {
        userPostFollowService.insertIgnoreNull(techUserPostFollow);
        return AjaxResult.success();
    }    
      
    /**
     * 修改，忽略null字段
     *
     * @param techUserPostFollow 修改的记录
     * @return 返回影响行数
     */
    @RequestMapping("update")
    public int update(@RequestBody TechUserPostFollow techUserPostFollow) {
        return userPostFollowService.updateIgnoreNull(techUserPostFollow);
    }
    
    /**
     * 取消关注
     *
     * @param techUserPostFollow 待删除的记录
     * @return 返回影响行数
     */
    @RequestMapping("delete")
    @ApiOperation("取消关注")
    public AjaxResult delete(@RequestBody TechUserPostFollow techUserPostFollow) {
        userPostFollowService.delete(techUserPostFollow);
        return AjaxResult.success();
    }
    
}